package com.msb.datastructure;

import java.util.Random;

/**
 * @author dataexa
 * @Date 2023/12/5
 */
public class CommonUtils {
    // 打印数组
    public static void printArray(int[] arr) {
        for (int value : arr) {
            System.out.print(value + " ");
        }
    }

    // 随机生成num个最大为maxValue的数
    public static int[] randomIntArray(int num, int maxValue) {
        int[] result = new int[num];
        Random random = new Random();
        for (int i = 0; i < num; i++) {
            int value = random.nextInt(maxValue);
            result[i] = value;
        }
        return result;
    }

    // 交换数组
    public static void swap(int[] arr, int a, int b) {
        int temp = arr[a];
        arr[a] = arr[b];
        arr[b] = temp;
    }
}
